﻿using System;
using System.Diagnostics;

namespace RaytracerLib
{
    public class Statistics
    {
        private Stopwatch m_stopWatch = new Stopwatch();

        public ulong IntersectionTested;
        public ulong ColorsCalculated;
        public ulong ShadowTests;

        public ulong RaysCreated;
        public ulong CameraRaysCreated;
        public ulong ShadowRaysCreated;
        public ulong RefractedRaysCreated;
        public ulong ReflectedRaysCreated;
        public ulong RayTotalInternalReflections;

        public ulong ReflectionCalculations;
        public ulong RefractionCalculations;
        public ulong FresnelCalculations;
        
        public ulong RaysToDepth;
        public ulong FindOuterObject;

        public void RenderStart(RenderStartPhase a_phase)
        {
            if (a_phase == RenderStartPhase.ResetStatistics)
                m_stopWatch.Start();
        }

        public string Report()
        {
            return String.Format("Render time: {0} \n",
                        m_stopWatch.Elapsed.ToString("g")) +
                   String.Format("Rays created: {0:n0} \n",
                        RaysCreated) +
                   String.Format("Rays cast from camera: {0:n0} \n",
                        CameraRaysCreated) +
                   String.Format("Rays reflected: {0:n0} \n",
                        ReflectedRaysCreated) +
                   String.Format("Rays refracted: {0:n0} \n",
                        RefractedRaysCreated) +
                   String.Format("Total internal reflections: {0:n0} \n",
                        RayTotalInternalReflections) +
                   String.Format("Rays cast toward lights: {0:n0} \n",
                        ShadowTests) +
                   String.Format("Shadow rays created: {0:n0} \n",
                        ShadowRaysCreated) +
                   String.Format("Reflection calculations: {0:n0} \n",
                        ReflectionCalculations) +
                   String.Format("Refraction calculations: {0:n0} \n",
                        RefractionCalculations) +
                   String.Format("Fresnel calculations: {0:n0} \n",
                        FresnelCalculations) +
                   String.Format("Find outer object: {0:n0} \n",
                        FindOuterObject) +
                   String.Format("Intersection tests: {0:n0} \n",
                        IntersectionTested) +
                   String.Format("Color calculations: {0:n0} \n",
                        ColorsCalculated) +
                   String.Format("Count of rays exceed max reflection numbers: {0:n0}",
                        RaysToDepth);
        }

        public void RenderEnd()
        {
            m_stopWatch.Stop();
        }
    }
}